ReactJS Ultra For Beginners

✍️ Introduction to JSX


What Is JSX?

  • A JavaScript syntax extension for writing HTML-like code in React
  • Makes UI code more readable and expressive
  • Transpiled to React.createElement calls under the hood

📝 Why Use JSX?

  1. Declarative: Describe what the UI should look like
  2. Familiar: Leverages HTML syntax you already know
  3. Powerful: Embed JavaScript expressions with {}

// Counter.jsx import React, { useState } from "react"; export default function Counter() { const [count, setCount] = useState(0); return ( <div> <h2>Current Count: {count}</h2> <button onClick={() => setCount(count + 1)}>Increment</button> </div> ); }
  • {count} injects the current state value
  • onClick={…} attaches event handlers in JSX